//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import competitionItem from '../comm/competitionItem.vue';
import { Image as VanImage } from 'vant';
import { scrollMixin } from "utils/mixin";

export default {
  name:'',
  mixins: [scrollMixin], //加载更多
  //import引入的组件需要注入到对象中才能使用
  components: {VanImage,competitionItem},
  data() {
  return {
    active:0,
    query:{
      title:'',
      activity_status:'',
      page:1,
    },
    totalPage:0,
    isLoadMore: true,
    tabArr:[
      {
        name:'全部',
        value:'',
      },
      {
        name:'进行中',
        value:2,
      },
      {
        name:'未开始',
        value:1,
      },
      {
        name:'已结束',
        value:3,
      }
    ],
    competitionArr:[
    ]
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    onSearch() {
      this.query.page = 1;
      this.competitionArr = [];
      this.goodsList();
    },
    initData() {
      this.query.page = 1;
      this.competitionArr = [];
    },
    compentChange(name,title) {
      this.initData();
      this.goodsList();
    },
    goodsList() {
      $http.get("plugin.event-registration.api.goods.goods.get-goods-list", this.query, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            this.isLoadMore = true;
            this.totalPage = res.last_page;
            if (!this.totalPage) {
              this.query.page = 0;
            }
            this.competitionArr = res.data;
          } else {
            this.query.page = this.query.page - 1;
            this.isLoadMore = false;
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.query.page >= this.totalPage) {
        return;
      } else {
        this.query.page  = this.query.page+1;
        $http.get("plugin.event-registration.api.goods.goods.get-goods-list", this.query, "正在获取").then(
          response => {
            if (response.result == 1) {
              let res = response.data;
              let list = res.data;
              this.isLoadMore = true;
              this.competitionArr = [...this.competitionArr, ...list];
            } else {
              this.query.page  = this.query.page - 1;
              this.isLoadMore = false;
              this.$dialog.alert({ message: response.msg });
            }
          },
          function(response) {
            // console.log(response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.initData();
    this.goodsList();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
}